﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data;
using YouErYuanModels;
using CommonLib;
using System.Data.SqlClient;

namespace YouErYuanBLL
{
    /// <summary>
    /// 班级业务处理
    /// </summary>
    public class TClassBLL
    {
        /// <summary>
        /// 批量设置幼儿园班级的签到查看截止日期，视频查看截止日期
        /// </summary>
        /// <param name="classIds">班级id数组</param>
        /// <param name="qiandaoDate">签到查看截止日期</param>
        /// <param name="videoDate">视频查看截止日期</param>
        /// <returns></returns>
        public int UpdateClassQiandaoVideoDate(string[] classIds, string qvDate)
        {
            List<object[]> list = new List<object[]>();
            string sql = "UPDATE [dbo].[T_Class] SET [qvEndDate] = @qvEndDate WHERE [id] = @id";
            foreach (string classId in classIds)
            {
                SqlParameter[] parmes = {
                    new SqlParameter("@id",classId),
                    new SqlParameter("@qvEndDate",qvDate)                    
                };
                object[] arr = new object[2];
                arr[0] = sql;
                arr[1] = parmes;
                list.Add(arr);
            }
            return SQLHepler.ExecSqlTransacation(list);
        }

        /// <summary>
        /// 根据学校主键查询所有的班级
        /// </summary>
        /// <param name="schoolId"></param>
        /// <returns></returns>
        public List<TClass> GetSchoolBanJi(string schoolId)
        {
            List<TClass> list = new List<TClass>();
            string sql = "SELECT [id],[className],[schoolId],Convert(varchar(30),[qvEndDate],23) as [qvEndDate] FROM [dbo].[T_Class] where [schoolId]=@schoolId ";
            DataTable dt = SQLHepler.GetDataSet(sql, new SqlParameter("@schoolId", schoolId)).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var item = dt.Rows[i];
                    TClass model = new TClass();
                    model.Id = item["id"].GetType() == typeof(System.DBNull) ? "" : Convert.ToString(item["id"]);
                    model.Classname = item["className"].GetType() == typeof(System.DBNull) ? "" : Convert.ToString(item["className"]);
                    model.Schoolid = item["schoolId"].GetType() == typeof(System.DBNull) ? "" : Convert.ToString(item["schoolId"]);
                    model.Qvdate = item["qvEndDate"].GetType() == typeof(System.DBNull) ? "" : Convert.ToString(item["qvEndDate"]);
                    list.Add(model);
                }
            }
            return list;
        }
        /// <summary>
        /// 新增班级
        /// </summary>
        /// <param name="tc"></param>
        /// <returns></returns>
        public int InsertClass(TClass tc)
        {
            string sql = "insert into T_Class values (newid(),@className,@schoolid,@qvEndDate)";
            SqlParameter[] parameter = new SqlParameter[] {
                new SqlParameter("@className",tc.Classname),new SqlParameter("@schoolid",tc.Schoolid),new SqlParameter("@qvEndDate",tc.Qvdate)
            };
            int count = SQLHepler.ExecuteSql(sql, parameter);
            return count;
        }

    }
}
